<?php

class StatisticsView extends View {

	protected $mostPopularMovies;
	protected $mostPopularDirectors;
	protected $mostPopularActors;

	function __construct() {
	
	}
	
	function getMostPopularMovies() {
		return $this->mostPopularMovies;
	}
	
	function setMostPopularMovies($m) {
		$this->mostPopularMovies = $m;
	}
	
	function getMostPopularDirectors() {
		return $this->mostPopularDirectors;
	}
	
	function setMostPopularDirectors($m) {
		$this->mostPopularDirectors = $m;
	}
	
	function getMostPopularActors() {
		return $this->mostPopularActors;
	}
	
	function setMostPopularActors($m) {
		$this->mostPopularActors = $m;
	}
	
	function display() {
		echo '<div style="width:90%">';
		echo '<h3 style="margin-bottom:10px">Most popular movies</h3>';
		echo '<table class="table table-striped">';
		echo '<thead><th>id</th><th>Title</th><th>Year of release</th><th>Director</th><th>Rating</th><th>Copies Available</th><th>Price</th></thead>';
		if ($this->mostPopularMovies) {
			foreach ($this->mostPopularMovies as $movie) {
				echo '<tr><td>'.$movie->getId().'</td>
						<td><a href="?page=store_manager&view=editMovie&movieId='
															.$movie->getId().'&movieName='.$movie->getTitle().'&noCopies='
															.$movie->getNoCopies().'">'.$movie->getTitle().'</a></td>
						<td>'.$movie->getYear().'</td>
						<td>'.$movie->getDirectorFirstName().' '.$movie->getDirectorLastName().'</td>
						<td>'.$movie->getRating().'</td>
						<td>'.$movie->getNoCopies().'</td>
						<td>'.$movie->getPrice().'</td>
						</tr>';
			}
		}
		echo '</table>';
		echo '<br />';
		echo '<hr />';
		echo '<br />';
		echo '<h3 style="margin-bottom:10px">Most popular directors</h3>';
		echo '<table class="table table-striped">';
		echo '<thead><th>id</th><th>Director first name</th><th>Director last name</th></thead>';
		if ($this->mostPopularDirectors) {
			foreach ($this->mostPopularDirectors as $director) {
				echo '<tr><td>'.$director->getId().'</td>
						<td>'.$director->getFirstName().'</td>
						<td>'.$director->getLastName().'</td>
						</tr>';
			}
		}
		echo '</table >';
		echo '<br />';
		echo '<hr />';
		echo '<br />';
		echo '<table class="table table-striped">';
		echo '<h3 style="margin-bottom:10px">Most popular actors</h3>';
		echo '<thead><th>id</th><th>Actor first name</th><th>Actor last name</th></thead>';
		if ($this->mostPopularMovies) {
			foreach ($this->mostPopularActors as $actor) {
				echo '<tr><td>'.$actor->getId().'</td>
						<td>'.$actor->getFirstName().'</td>
						<td>'.$actor->getLastName().'</td>
						</tr>';
			}
		}
		echo '</table>';
		echo '</div>';
	}
	
}